import { WebView, View, Text } from '@tarojs/components'
import { useMemo } from 'react'
import { useRouter } from '@tarojs/taro'

import './index.scss'

const WebviewPage = () => {
  const router = useRouter()
  const target = useMemo(() => {
    const url = router.params?.target
    try {
      return url ? decodeURIComponent(url) : ''
    } catch (error) {
      return url || ''
    }
  }, [router.params])

  if (!target) {
    return (
      <View className='webview-empty'>
        <Text>未找到可打开的链接</Text>
      </View>
    )
  }

  return <WebView src={target} />
}

export default WebviewPage
